#!/usr/bin/bash

#============================================
# 我的控制面板
# 参考：https://www.imooc.com/video/10108
#============================================

clear
#初始化终端颜色，即清除颜色
resetTerminal=$(tput sgr0)
GREEN='\e[1;32m'

# declare -A arrShell
# i=0
# numbers=""
# echo -e "${GREEN}╔═══════ 我的控制面板 ═══════╗${resetTerminal}"
# for shellFile in $(ls -I "superman.sh" ./); do #遍历shell文件，除superman.sh以外
#     printf "%-10s %-8s ${GREEN}║ [${i}] $shellFile ║\n${resetTerminal}" 
#     arrShell[$i]=${shellFile}
#     numbers="${numbers} | ${i}"
#     let "i++"
# done
# echo -e "${GREEN}╚══════ 输入非数字即可退出 ═════╝${resetTerminal}"

# while true; do
#     read -p "请选择[ ${numbers} ]: " selectValue
#     if [[ ! ${selectValue} =~ ^[0-9]+ ]]; then
#         exit 0
#     fi
#     /bin/bash ./${arrShell[$selectValue]}
# done


echo -e "${GREEN}╔══════════ 我的控制面板 ═════════╗"
        echo -e "║   [1] 系统资源监控                                 ║"
        echo -e "║   [2] Nginx网站监控                                ║"
        echo -e "║   [3] Nginx日志分析                                ║"
        echo -e "║   [4] MySQL服务及主从状态监控                      ║"
        echo -e "╚═════════ 输入q或Q即可退出 ════════╝${resetTerminal}"

declare -A arrShell
arrShell[1]="system_moniter.sh"
arrShell[2]="check_nginx.sh"
arrShell[3]="nginx_log.sh"
arrShell[4]="check_mysql.sh"

while true; do
    read -p "请选择: " selectValue
    if [[ ${selectValue} == 'q' || ${selectValue} == 'Q' ]]; then
        exit 0
    fi
    if [[ ! ${selectValue} =~ ^[1-3]+ ]]; then # ^[0-9]+ 正则匹配数字
        #exit 0
        continue
    fi    
    /bin/bash ./${arrShell[$selectValue]}
done